﻿using System;
using System.ComponentModel;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;

using DevExpress.ExpressApp;
using DevExpress.ExpressApp.Actions;
using DevExpress.Persistent.Base;
using DevExpress.ExpressApp.Win.Editors;
using DevExpress.ExpressApp.Reports;
using DevExpress.Data.Filtering;
using Ascent.QiPei.Module.Win.Sales;

namespace Ascent.QiPei.Module.Win.Controllers
{
    public partial class SaleOrderViewController : ViewController
    {
        public SaleOrderViewController()
        {
            InitializeComponent();
            RegisterActions(components);
        }

        private void SaleOrderViewController_ViewControlsCreated(object sender, EventArgs e)
        {
            GridListEditor listEditor = ((ListView)View).Editor as GridListEditor;
            if (listEditor != null)
            {
                listEditor.Grid.DoubleClick += Grid_DoubleClick;
            }
        }

        void Grid_DoubleClick(object sender, EventArgs e)
        {
            //ReportData reportdata = ObjectSpace.FindObject<ReportData>(new BinaryOperator("Name", "销售单"));
            //if (reportdata != null)
            //{
            //    XafReport rep1 = reportdata.LoadXtraReport(ObjectSpace);
            //    if (View.CurrentObject != null)
            //    {
            //        var o = View.CurrentObject as BusinessObjects.Sales.SaleOrder;
            //        if (!string.IsNullOrEmpty(o.SOCode))
            //            rep1.Parameters["SaleCode"].Value = o.SOCode;
            //        else
            //            rep1.Parameters["SaleCode"].Value = "XS001";
            //    }

            //    rep1.Parameters["SaleCode"].Visible = false;
            //    rep1.ShowPreviewDialog();
            //}
            if (View.CurrentObject != null)
            {
                var o = View.CurrentObject as BusinessObjects.Sales.SaleOrder;
                SaleOrderForm saleOrderForm = new SaleOrderForm(ObjectSpace);
                saleOrderForm.currSaleOrder = o;
                saleOrderForm.ShowDialog();
            }
        }

        private void SaleOrderViewController_ViewControlsDestroying(object sender, EventArgs e)
        {
            GridListEditor listEditor = ((ListView)View).Editor as GridListEditor;
            if (listEditor != null)
            {
                listEditor.Grid.DoubleClick -= Grid_DoubleClick;
            }
        }
    }
}
